from google.appengine.dist import use_library 
use_library('django', '1.2')

from google.appengine.ext import webapp
from schema import NodeSchema
from google.appengine.ext.db import djangoforms
from django import forms
from pprint import pprint

#print pprint(dir(djangoforms))

class TinyMCE(djangoforms.forms.TextInput):
	def __init__(self, attrs = None):
		super(TinyMCE, self).__init__(attrs)
		pass
	def render(self, name, value, attrs = None):
		return "text widget"
		
class Module:
	def __init__(self):
		self.urls = [
			(r'/node/view/(.*)', self.ViewHandler),
			(r'/node/submit/', self.SubmitHandler)
		]
		pass
	
	class ViewHandler(webapp.RequestHandler):
		def get(self, count):	
			f = Module.NodeForm()
			return self.response.out.write(Module.NodeForm())
			pass 
			
	class SubmitHandler(webapp.RequestHandler):
		def post(self, count):	
			f = Module.NodeForm()
			return self.response.out.write(Module.NodeForm())
			pass 
			
	class NodeForm(djangoforms.ModelForm):
		def __init__(self, *args, **kwargs):
			super(Module.NodeForm, self).__init__(*args, **kwargs)
			self.fields['title'].widget = TinyMCE()
			
		class Meta:
			model = NodeSchema
			#fields = ('title')
			#widgets = {'title': TinyMCE,}
